/**
 * @author LKQ
 * @date 2022/2/2 15:29
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.hammingDistance(1, 4);
    }
    public int hammingDistance(int x, int y) {
        StringBuffer x1 = new StringBuffer(), y1 = new StringBuffer();
        while (x != 0) {
            x1.append(x % 2);
            x /= 2;
        }
        while (y != 0) {
            y1.append(y % 2);
            y /= 2;
        }
        x1 = x1.reverse();
        y1 = y1.reverse();
        String X = "", Y = "";
        if (y1.length() > x1.length()) {
            for (int i = 0; i < y1.length() - x1.length(); i++) {
                X += "0";
            }
            X += x1.toString();
            Y += y1.toString();
        }else {
            for (int i = 0; i < x1.length() - y1.length(); i++) {
                Y += "0";
            }
            X += x1.toString();
            Y += y1.toString();
        }
        int ans = 0;
        for (int i = 0; i < X.length(); i++) {
            if (X.charAt(i) != Y.charAt(i)) {
                ans++;
            }
        }
        return ans;
    }
}
